package 力扣._2766_重新放置石块;

import java.util.*;

class Solution {
    public List<Integer> relocateMarbles(int[] nums, int[] moveFrom, int[] moveTo) {
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            if (map.containsKey(nums[i])) {
                map.put(nums[i], map.get(nums[i]) + 1);
            } else map.put(nums[i], 1);
        }
        for (int i = 0; i < moveFrom.length; i++) {
            System.out.println(i);
            if (map.containsKey(moveTo[i])) {
                map.put(moveTo[i], map.get(moveTo[i]) + map.get(moveFrom[i]));
            } else map.put(moveTo[i], map.get(moveFrom[i]));
            if (moveFrom[i] != moveTo[i])
                map.remove(moveFrom[i]);

        }
        Set<Integer> set = map.keySet();
        List<Integer> list = new ArrayList<>(set.stream().toList());
        list.sort((Comparator.comparingInt(o -> o)));
        return list;

    }

    public static void main(String[] args) {
        int[] nums = new int[]{3, 4};
        int[] moveFrom = new int[]{4, 3, 1, 2, 2, 3, 2, 4, 1};
        int[] moveTo = new int[]{3, 1, 2, 2, 3, 2, 4, 1, 1};
        new Solution().relocateMarbles(nums, moveFrom, moveTo);
    }
}